package com.itheima.web;

import com.itheima.pojo.Student;
import com.itheima.pojo.User;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

import java.util.List;
import java.util.Map;
import java.util.Set;

@Controller//web层 注解扫包
public class HellController {

    /**
     * 访问的网址为 http://localhost:8080/Hello
     * @return
     */
    @RequestMapping("Hello")
    public String hello(){
        return "hello";
    }
   /* @RequestMapping("/*")
    public String findAll(){
        return "hello";
    }*/


    @RequestMapping(value = "hello1",method = {RequestMethod.GET,RequestMethod.POST} )
    public String method1(String name,String age){
        System.out.println("name="+name);
        System.out.println("age="+age);
        return "hello1";
    }

    @RequestMapping("hello2")
    public String method2(User user){
        System.out.println("User="+user);
        return "hello2";
    }

    @RequestMapping(value = "hello3",method = RequestMethod.GET,params = {"name","age"})
    public String method3(@RequestParam("name")String userName,String address){
        System.out.println("userName="+userName);
        System.out.println("address="+address);
        return "hello2";
    }
    @RequestMapping(value = "hello4",headers = {"name","age"})
    public String method4(@RequestParam("name")String userName,String address){
        System.out.println("userName="+userName);
        System.out.println("address="+address);
        return "hello2";
    }
    @RequestMapping(value = "hello5",method = RequestMethod.GET)
    public String method5(User user){
        List<String> list = user.getUserList();
        for (String s : list) {
            System.out.println("s = " + s);
        }
        return "hello1";
    }

    @RequestMapping(value = "hello6",method = RequestMethod.GET)
    public String method6(User user){
        List<Student> list = user.getStuList();
        for (Student s : list) {
            System.out.println(s.toString());
        }
        return "hello1";
    }
    @RequestMapping(value = "hello7",method = RequestMethod.GET)
    public String method7(User user){
        Map<String, String> userMap = user.getUserMap();
        Set<String> strings = userMap.keySet();
        for (String key : strings) {
            String value = userMap.get(key);
            System.out.println("value = " + value);
        }
        return "hello1";
    }
    @RequestMapping(value = "hello8",method = RequestMethod.GET)
    public String method8(String[] names){
        for (String name : names) {
            System.out.println("name = " + name);
        }


        return "hello1";
    }
}
